/*
 * GraphWindow.h
 *
 *  Created on: Apr 10, 2011
 *      Author: Matthew Michelotti
 */

#pragma once

#include <sfv/array1d.h>
#include <sfv/csr_matrix.h>

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Gl_Window.H>
#include "Color.h"
#include "VisualNode.h"
#include <vector>
#include "HNode.h"

class GraphWindow : public Fl_Gl_Window {
	void draw();
	int handle(int);

public:
	virtual ~GraphWindow();

	//static int begin();
	static int begin(const sfv::csr_matrix<int,float>& A,
					const sfv::array1d<double>& x,
					const sfv::array1d<double>& y);
	static int begin(HNode* root);

	static const int screenWidth;
	static const int screenHeight;

private:
	GraphWindow(int X, int Y, int W, int H, const char *L)
	    : Fl_Gl_Window(X, Y, W, H, L), num_of_redraws(0), num_of_clicks(0) {}

	void fillBox(double x, double y, double w, double h, Color c);
	void fillCircle(double x, double y, double r, Color c);
	void drawLine(double x1, double y1, double x2, double y2, Color c);

	void forceStep();
	void onClick(int node);

	static void callback(void*);

	double getNodeRadius(int size);


	static GraphWindow* activeWindow;

	static const Color edgeColor;
	static const Color nodeColor;

	sfv::csr_matrix<int,float> matrix;
	VisualNode* nodeArray;
	size_t num_of_redraws;
	size_t num_of_clicks;

	std::vector<HNode*> hnodes;

	typedef unsigned int uint;
};
